//var cmd=process.platform=='win32'?'netstat -ano':'ps aux';

var p = "8000";
var cmd=process.platform=='win32'?'netstat -ano|find "'+p+'"' :'ps aux';
var exec = require('child_process').exec;
var qqname='qq';
var port='3392';

var str = '';

//exec('php ../think run');
exec(cmd, function(err, stdout, stderr) {
    if(err){ return console.log(err); }
	if(stdout){
		var p=stdout.trim().split(/\s+/); 
		str = 'taskkill /pid  '+ p[4] +' /F';
		console.log(p[4],str)
		exec(str)
	}
});

/*

stdout.split('\n').filter(function(line){        
        var p=line.trim().split(/\s+/); 
		console.log(p)
        var address=p[1];        
        if(address!=undefined){        
            if(address.split(':')[1]==port)
            {                
                exec('taskkill /F /pid '+p[4],function(err, stdout, stderr){
                    if(err){
                        return console.log('释放指定端口失败！！');    
                    }
                    
                    console.log('占用指定端口的程序被成功杀掉！');
                });
            }
        }                          
    });
*/